﻿Imports wys.util.http
Imports System.Net
Imports System.Text
Imports System.Web

Public Class CNBLOG

    Private _httpBase As HttpBase
    Private Sub btn登录百度_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn登录百度.Click
        _httpBase = New HttpBase(Cookie模型.默认)

        '打开登录网页
        Dim ht As New Hashtable
        ht.Add(HttpRequestHeader.Referer, "http://www.cnblogs.com/")
        ht.Add(HttpRequestHeader.KeepAlive, "Keep-Alive")
        ht.Add(HttpRequestHeader.AcceptLanguage, "zh-cn")
        Dim content As String = _httpBase.获取网页内容("http://passport.cnblogs.com/login.aspx?ReturnUrl=http://www.cnblogs.com/", ht, False, False)

        '登陆
        ht = New Hashtable
        ht.Add(HttpRequestHeader.Referer, "http://passport.cnblogs.com/login.aspx?ReturnUrl=http://www.cnblogs.com/")
        ht.Add(HttpRequestHeader.KeepAlive, "Keep-Alive")
        ht.Add(HttpRequestHeader.AcceptLanguage, "zh-cn")

        Dim sb As New StringBuilder
        sb.Append("__EVENTTARGET=" & HttpUtility.UrlEncode(HttpUtil.GetHiddenValueFormName(content, "__EVENTTARGET")))
        sb.Append("&__EVENTARGUMENT=" & HttpUtility.UrlEncode(HttpUtil.GetHiddenValueFormName(content, "__EVENTARGUMENT")))
        sb.Append("&__VIEWSTATE=" & HttpUtility.UrlEncode(HttpUtil.GetHiddenValueFormName(content, "__VIEWSTATE")))
        sb.Append("&__EVENTVALIDATION=" & HttpUtility.UrlEncode(HttpUtil.GetHiddenValueFormName(content, "__EVENTVALIDATION")))
        sb.Append("&tbUserName=wang284008476")
        sb.Append("&tbPassword=7758521")
        sb.Append("&btnLogin=" & HttpUtility.UrlEncode("登  录"))
        sb.Append("&txtReturnUrl=" & HttpUtility.UrlEncode("http://www.cnblogs.com/"))

        ht.Add("PostData", sb.ToString)
        _httpBase.获取网页内容("http://passport.cnblogs.com/login.aspx?ReturnUrl=" & HttpUtility.UrlEncode("http://www.cnblogs.com/"), ht, False, True)

        '打开设置画面 设置COOKIE是否正确
        ht = New Hashtable
        ht.Add(HttpRequestHeader.KeepAlive, "Keep-Alive")
        ht.Add(HttpRequestHeader.AcceptLanguage, "zh-cn")
        ht.Add(HttpRequestHeader.Referer, "http://home.cnblogs.com/")
        _httpBase.获取网页内容("http://home.cnblogs.com/set/avatar/", ht, False, False)

    End Sub

End Class